package sk.lukaskrupa.guess.the.color.listeners;

import sk.lukaskrupa.guess.the.color.logging.Logging;
import sk.lukaskrupa.guess.the.color.ui.Game;
import sk.lukaskrupa.guess.the.color.ui.R;
import android.view.View;
import android.view.View.OnClickListener;

/**
 * Listen to game activity buttons.
 * 
 * @author Lukas Krupa (lukas0krupa@gmail.com)
 * 
 */
public class GameButtonListener implements OnClickListener {

	private static Logging logger = Logging.getLog(GameButtonListener.class);
	private final Game game;

	/**
	 * Constructs listener and save reference to Game activity
	 * 
	 * @param game
	 *            to be used for closeing
	 */
	public GameButtonListener(Game game) {
		this.game = game;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void onClick(View v) {

		logger.debug("onClick", "You clicked on button with ID=" + v.getId());
		if (v.getId() == R.id.sendGame) {

			if (this.game.isComplete()) {
				logger.info("onClick", "Sending guess.");
				this.game.validateInput();
			} else {
				logger.info("onClick", "Guess isn't complete");
			}

		} else if (v.getId() == R.id.giveUpGame) {

			logger.info("onClick", "Giving up.");
			this.game.giveUp();
		} else if (v.getId() == R.id.backToMenuGame) {

			logger.info("onClick", "Exiting game to menu.");
			this.game.finish();
		}

	}

}
